<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CityLogic
 *
 * @author Administrator
 */
class CityLogic extends BaseLogic{
    //put your code here
    private $cityTable;
    public function __construct() {
        parent::__construct();
        $this->cityTable=  $this->load("city");
        $this->table=  $this->cityTable;
    }
    /**
     * 通过省份id获得城市列表
     * @param type $pid 省份id
     * @return boolean  城市列表
     */
    public function getCityListByPid($pid){
        if($pid){
            $res=$this->cityTable->select("*","provinceID={$pid}");
            return $res;
        }
        return FALSE;
    }
 /**
  * 通过id获得城市信息
  * @param type $id 城市id
  * @return boolean 城市信息
  */
    public function getCityInfoById($id){
        if($id){
            $res=  $this->cityTable->get_one("*","id={$id}");
            return $res;
        }
        return FALSE;
    }
    /**
     * 通过城市名称获得城市id
     * @param type $name 城市名称
     * @return int  城市id
     */
     public function getIdByName($name){
        if($name){
            $res=  $this->cityTable->get_one("*","city like '{$name}%'");
            return $res["id"];
        }
        return 0;
    }
    
    /**
     *    保存和更新城市列表
     * @param type $data 城市信息
     * @param type $id   城市id
     * @return type  
     */
    public function save($data,$id=0){
        if($id>0){
            $res=  $this->cityTable->update($data,"id={$id}");
        }else{
            $res=$this->cityTable->insert($data,TRUE);
        }
        return $res;
    }
       /**
     * 获得含有中国天气网id的城市列表
     * @return boolean  地区列表， 否则返回false
     */
    public function getHasWeatherAll(){
        $res=  $this->table->select("weatherID,id","weatherID is NOT NULL GROUP BY weatherID");
        if($res)
        {
            return $res;
        }
        return FALSE;
    }
}
